package cn.tedu.nullpoint;

public class NullPointDemo {
    public static void main(String[] args) {
        //创建对象
//        Person p = new Person();//p=0x001
//        p.name = "张三";
//        p.eat();
//        p = null;//p=null
//        //p.eat();
//        System.out.println(p);
        Person p = null;
        int num = -6;
        if(num>0){
            p = new Person();
        }
        System.out.println(p);
        if(p==null){
            System.out.println(p.name);
        }
        p = null;//提前释放对象
        System.out.println("hello");
        System.out.println("hi");
        //1000
    }
}
class Person{
    String name;
    int age;
    public void eat(){
        System.out.println("吃饭~~");
    }
    public Person(){}
    //提供有参构造 不再生成无参构造
    public Person(String name,int age){
        this.name = name;
    }
}
